package com.missilike.admin.controller;


import com.missilike.biz.IMilJournalDetailService;
import com.missilike.core.result.CommonResult;
import com.missilike.core.utils.ResultUtils;
import com.missilike.domain.request.MilJournalDetailForm;
import com.missilike.domain.request.MilJournalDetailStatusForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kin
 * @since 2018-12-25
 */
@RestController
@RequestMapping("/api/mil/journal_detail")
public class MilJournalDetailController {

    private final IMilJournalDetailService milJournalDetailService;

    @Autowired
    public MilJournalDetailController(IMilJournalDetailService milJournalDetailService) {
        this.milJournalDetailService = milJournalDetailService;
    }

    @RequestMapping(value = "info/{journalId}", method = RequestMethod.GET)
    public CommonResult info(@PathVariable("journalId") int journalId) {
        return ResultUtils.ok(milJournalDetailService.getById(journalId));
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public CommonResult save(@ModelAttribute MilJournalDetailForm milJournalDetailForm) {
        milJournalDetailService.upsert(milJournalDetailForm);
        return ResultUtils.ok();
    }

    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public CommonResult delete(@RequestBody Integer[] journalIds) {
        milJournalDetailService.removeByIds(Arrays.asList(journalIds));
        return ResultUtils.ok();
    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    public CommonResult update(@ModelAttribute MilJournalDetailForm milJournalDetailForm) {
        milJournalDetailService.upsert(milJournalDetailForm);
        return ResultUtils.ok();
    }

    @RequestMapping(value = "status", method = RequestMethod.POST)
    public CommonResult status(@RequestBody MilJournalDetailStatusForm milJournalDetailStatusForm) {
        milJournalDetailService.status(milJournalDetailStatusForm);
        return ResultUtils.ok();
    }
}

